/* 
 * Copyright 2011 QDSS.org. All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.qdss.oapi4j;

import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Api调用参数
 * 
 * @author <a href="mailto:zhaofang123@gmail.com">Zhao Fangfang</a>
 * @date 2011-3-20
 * @version $Id: ApiParameter.java 39 2011-09-27 10:41:37Z zhaofang123@gmail.com $
 */
public class ApiParameter {
	
	private final String apiUrl;
	private final String authzToken;
	
	private final Map<String, Object> params;
	private Set<String> longParamsKey;
	
	/**
	 * @param apiUrl
	 */
	public ApiParameter(String apiUrl) {
		this(apiUrl, null);
	}
	
	/**
	 * @param apiUrl
	 * @param authzToken
	 */
	public ApiParameter(String apiUrl, String authzToken) {
		this.apiUrl = apiUrl;
		this.authzToken = authzToken;
		this.params = new HashMap<String, Object>();
	}
	
	/**
	 * 获取API调用地址
	 * 
	 * @return
	 */
	public String getApiUrl() {
		return apiUrl;
	}
	
	/**
	 * 获取授权码
	 * 
	 * @return
	 */
	public String getAuthzToken() {
		return authzToken;
	}
	
	/**
	 * @return
	 */
	public Map<String, Object> getParams() {
		return params;
	}
	
	/**
	 * @return
	 */
	public Set<String> getLongParamsKey() {
		return longParamsKey;
	}
	
	/**
	 * 添加文本参数
	 * 
	 * @param key
	 * @param strValue
	 * @return
	 */
	public ApiParameter addParam(String key, String strValue) {
		params.put(key, strValue);
		return this;
	}
	
	/**
	 * 添加数字参数
	 * 
	 * @param key
	 * @param numValue
	 * @return
	 */
	public ApiParameter addParam(String key, Number numValue) {
		return addParam(key, numValue.toString());
	}
	
	/**
	 * 添加二进制参数（如图片）。此参数不参与编码
	 * 
	 * @param key
	 * @param fileValue
	 * @return
	 */
	public ApiParameter addParam(String key, File fileValue) {
		return addLongParam(key, fileValue);
	}
	
	/**
	 * 添加大参数（如商品的描述）。此参数不参与编码
	 * 
	 * @param key
	 * @param value
	 * @return
	 */
	public ApiParameter addLongParam(String key, Object value) {
		if (longParamsKey == null) {
			longParamsKey = new HashSet<String>();
		}
		longParamsKey.add(key);
		params.put(key, value);
		return this;
	}
}
